﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Parts_Users_BirthdaysNotOffice : System.Web.UI.Page
{

    string[] _MonthName = { "Января", "Февраля", "Марта", "Апреля", "Мая", "Июня", "Июля", "Августа", "Сентября", "	Октября", "Ноября", "Декабря" };

    protected void Page_Load(object sender, EventArgs e)
    {
        Ko2.Portal.SP_List.SPList_BirthdaysAll o = new Ko2.Portal.SP_List.SPList_BirthdaysAll();
        DataTable tbl = new DataTable("tbl");
        List<string> errList = new List<string>();
        Exception ret = o.SelectFromWS(ref tbl, ref errList);
        if (ret == null)
        {

            //oTbl.Caption = "The table";

            foreach (DataRow r in tbl.Rows)
            {

                bool IsOffice = false;
                if (r["IsOffice"] != DBNull.Value)
                    IsOffice = (bool)((string)r["IsOffice"] == "1" ? true : false);

                if (IsOffice == false)
                    continue;

                TableRow newr = new TableRow();

                string Img = "";
                string[] ImgTmp;
                string[] ImgSeparator = { @"http://" };
                if (r["Img"] != DBNull.Value)
                    Img = (string)r["Img"];
                ImgTmp = Img.Split(ImgSeparator, StringSplitOptions.RemoveEmptyEntries);
                if (ImgTmp.Length > 0)
                {
                    Img = ImgTmp[ImgTmp.Length - 1];
                    if (!String.IsNullOrEmpty(Img))
                    {
                        TableCell cellImg = new TableCell();
                        Image oImg = new Image();
                        oImg.ImageUrl = @"http://" + Img;
                        oImg.Height = 130;
                        //oImg.Width = 114;
                        cellImg.Controls.Add(oImg);
                        newr.Cells.Add(cellImg);
                    }
                }

                string UserName = "";
                if (r["UserName"] != DBNull.Value)
                    UserName = (string)r["UserName"];
                string WebSite = "";
                if (r["WebSite"] != DBNull.Value)
                    WebSite = @"http://sp.korablik.local/" + (string)r["WebSite"];
                string UserProfile_GUID = "";
                if (r["UserProfile_GUID"] != DBNull.Value)
                    UserProfile_GUID = (string)r["UserProfile_GUID"];

                DateTime dt;
                TableCell cellBody = new TableCell();
                if (r["DT"] != DBNull.Value)
                {
                    dt = (DateTime)r["DT"];
                    Label l2 = new Label();
                    l2.Text = dt.Day.ToString() + " "
                        + _MonthName[dt.Month - 1] + "<br>";
                    l2.Font.Size = 10;
                    l2.Font.Bold = true;
                    l2.ForeColor = System.Drawing.Color.Blue;
                    cellBody.Controls.Add(l2);
                }

                string DisplayName = "";
                if (r["Title"] != DBNull.Value)
                {
                    DisplayName = (string)r["Title"];
                    HyperLink o2 = new HyperLink();
                    o2.Text = DisplayName;
                    o2.NavigateUrl = WebSite;
                    o2.Target = "_parent";
                    cellBody.Controls.Add(o2);
                    Label l2 = new Label();
                    l2.Text = @"<br />";
                    cellBody.Controls.Add(l2);
                }

                string OfficeName = "";
                if (r["OfficeName"] != DBNull.Value)
                {
                    OfficeName = (string)r["OfficeName"];
                    Label l2 = new Label();
                    l2.Text = OfficeName + @"<br />";
                    cellBody.Controls.Add(l2);
                }

                string jobName = "";
                if (r["jobName"] != DBNull.Value)
                {
                    jobName = (string)r["jobName"];
                    Label l2 = new Label();
                    l2.Text = jobName + @"<br />";
                    cellBody.Controls.Add(l2);
                }

                string DepartmentName = "";
                if (r["DepartmentName"] != DBNull.Value)
                {
                    DepartmentName = (string)r["DepartmentName"];
                    Label l2 = new Label();
                    l2.Text = DepartmentName + @"<br />";
                    cellBody.Controls.Add(l2);
                }

                string EMail = "";
                if (r["EMail"] != DBNull.Value)
                {
                    EMail = (string)r["EMail"];
                    HyperLink o2 = new HyperLink();
                    o2.Text = EMail;
                    o2.NavigateUrl = @"mailto:" + EMail;
                    cellBody.Controls.Add(o2);
                    Label l2 = new Label();
                    l2.Text = @"<br />";
                    cellBody.Controls.Add(l2);
                }

                string Phone = "";
                if (r["Phone"] != DBNull.Value)
                {
                    Phone = (string)r["Phone"];
                    Label l2 = new Label();
                    l2.Text = "т. " + Phone + @"<br />";
                    cellBody.Controls.Add(l2);
                }

                newr.Cells.Add(cellBody);
                oTbl.Rows.Add(newr);
            }
        }
        else
        {
            Response.Write("Error : " + ret.Message);
        }
    }

}